<!DOCTYPE html>
<html>
    <head>
        <script src="/w3c/resources/testharness.js"></script>
        <script src="/w3c/resources/testharnessreport.js"></script>
        <script src="mediasource-util.js"></script>
        <link rel='stylesheet' href='/w3c/resources/testharness.css'>
    </head>
    <body>
        <div id="log"></div>
        <script>
          mediasource_testafterdataloaded(function(test, mediaElement, mediaSource, segmentInfo, sourceBuffer, mediaData)
          {
              test.failOnEvent(mediaElement, 'error');

              assert_false(sourceBuffer.updating, "sourceBuffer.updating");

              sourceBuffer.appendBuffer(mediaData);

              assert_true(sourceBuffer.updating, "sourceBuffer.updating");
              test.expectEvent(sourceBuffer, "updateend");

              test.waitForExpectedEvents(function()
              {
                  assert_false(sourceBuffer.updating, "sourceBuffer.updating");

                  // Truncate the buffered media to about 1 second duration.
                  sourceBuffer.remove(1, +Infinity);

                  assert_true(sourceBuffer.updating, "sourceBuffer.updating");
                  test.expectEvent(sourceBuffer, "updateend");
              });

              test.waitForExpectedEvents(function()
              {
                  mediaSource.endOfStream();
                  mediaElement.play();

                  test.endOnEvent(mediaElement, 'ended');
              });

          }, "Test normal playback case with MediaSource API", {timeout: 5000});
        </script>
    </body>
</html>
